//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	Smart.Common.Jobs.EventReceiver.cs
//  Developer:	Solomatov Igor
//  Created:	03.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System.Runtime.InteropServices;
using Microsoft.SharePoint;
using Smart.Common.Jobs;

namespace Smart.Common.Features
{
	/// <summary>
	/// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
	/// </summary>
	/// <remarks>
	/// The GUID attached to this class may be used during packaging and should not be modified.
	/// </remarks>
	[Guid("434e21f3-0131-4479-93fe-ad61c6e48944")]
	public class SPCommonJobsEventReceiver : SPFeatureReceiver
	{
		public override void FeatureActivated(SPFeatureReceiverProperties properties)
		{
			var site = properties.Feature.Parent as SPSite;

			using (SPH.SetContext(site, site.RootWeb))
			{
				var job = new SPCommonJobs();

				job.Register(SPH.GetWeb());
			}
		}

		public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
		{
			var site = properties.Feature.Parent as SPSite;

			using (SPH.SetContext(site, site.RootWeb))
			{
				var job = new SPCommonJobs();

				job.Unregister(SPH.GetWeb());
			}
		}
	}
}